package br.com.pontoclass.primes;

import java.math.BigInteger;
import java.util.logging.Level;
import java.util.logging.Logger;

import br.com.pontoclass.patterns.StoppablePrimeNumberListener;


public class ThreadBasedPrimeNumberListener implements StoppablePrimeNumberListener {

    private static final Logger LOGGER = Logger.getLogger(ThreadBasedPrimeNumberListener.class.getName());
    private StoppablePrimeNumberListener task;
    
    
    public ThreadBasedPrimeNumberListener(StoppablePrimeNumberListener task) {
        this.task = task;
        Thread thread = new Thread(task);
        thread.start();
//        try {
//            thread.join();
//        } catch (InterruptedException e) {
//            LOGGER.log(Level.SEVERE, "Thread was interrupted while trying to make a join on it.", e);
//        }
    }

    @Override
    public void onAddPrime(BigInteger number) {
        task.onAddPrime(number);
    }

    @Override
    public void stop() {
        task.stop();
    }

    @Override
    public void run() {
        //Nothing to do, delegating to the task...
    }
}
